<%@page import="com.project.vo.Product"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%
	List<User> users = (List<User>) request.getAttribute(StringUtil.USERS);
	Integer countNum = (Integer) request.getAttribute(StringUtil.COUNTNUM);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<%@ include file="/WEB-INF/jsp/include/head.jsp"%>
<title>查看用户信息</title>
<script type="text/javascript">
	function pageChange(pageNum) {
		var basepath = $("#basepath").val().trim();
		var $tbody = $("#user");
		var url = basepath + "/ajax/viewAllUser?pageNum=" + pageNum;
		$.ajax({
			url : url,
			type : "POST",
			data : {},
			contentType : "application/json",
			dataType : "json",
			cache : false,
			success : function(data) {
				var d = eval("(" + data + ")");//将数据转换成json类型
				html = "";
				users = d.result;
				for(var i=0; i<users.length; i++){
					html= html+"<tr><td>"+users[i].id+"</td><td><a href='admin/user/view?id="+users[i].id+"'>"
					+users[i].name +"</a></td><td>"
					+users[i].phone +"</td><td>"
					+users[i].email +"</td><td>"
					+users[i].IDCard +"</td><td>"
					+users[i].description +"</td><td>"
					+"<a href='admin/user/editJSP?id="+users[i].id+"'><label class='btn'>"+ "修改"+"<label></a></td><td>"
					+"<a href='admin/user/delete?id="+users[i].id+"'><label class='btn'>"+"删除" +"<label></a></td>"
					+"</tr>";
				}
// 				+"<a href='product/view?id="+products[i].id+"'><label class='btn'>"+"查看" +"<label></a></td><td>"
				$tbody.html("");
				$tbody.html(html);
			},
			error : function(data) {
				alert(data.responseText);
			}
		});
	}
</script>
</head>
<body>
	<%@ include file="/WEB-INF/jsp/include/admin/top.jsp"%>
	<%@ include file="/WEB-INF/jsp/include/admin/left.jsp"%>
	<input type="hidden" value="<%=basePath%>" id="basepath">
	<div class="main col-lg-9 col-md-9 col-xs-12 col-sm-12">
		<%
			if (users.isEmpty()) {
		%>
		<div class="col-lg-8 col-md-8 col-md-push-2 col-xs-12 col-sm-12"
			style="margin-top: 20px;">
			<form action="product/addJSP" method="post">
				<label>还没有用户注册</label> <input type="submit" class="btn"
					value="立即上传 ">
			</form>
		</div>
		<%
			} else {
		%>
		<table class="table col-lg-12 col-md-12 col-xs-12 col-sm-12">
			<tr>
				<th><%=StringUtil.U_ID %></th>
				<th><%=StringUtil.U_NAME%></th>
				<th><%=StringUtil.U_PHONE%></th>
				<th><%=StringUtil.U_EMAIL%></th>
				<th><%=StringUtil.U_IDCARD%></th>
				<th><%=StringUtil.U_DESCRIPTION%></th>
			</tr>
			<tbody id="user">
				<%
					for (User tUser : users) {
				%>

				<tr>
					<td><%=tUser.getId()%></td>
					<td><a href="admin/user/view?id=<%=tUser.getId()%>"><%=tUser.getName()%></a></td>
					<td><%=tUser.getPhone()%></td>
					<td><%=tUser.getEmail()%></td>
					<td><%=tUser.getIDCard()%></td>
					<td><%=tUser.getDescription()%></td>
					<td><a href="admin/user/editJSP?id=<%=tUser.getId()%>"><label
							class="btn"><%=StringUtil.O_EDIT%><label></a></td>
					<td><a href="admin/user/delete?id=<%=tUser.getId()%>"><label
							class="btn"><%=StringUtil.O_DELETE%><label></a></td>
				</tr>

				<%
					}
				%>
			</tbody>
		</table>
		<div>
			<!-- 			<a href="product/viewAll?pageNum=1" onclick="javascript:page();">[首页]</a> -->
			<ul class="pagination pagination-sm">
				<!-- 			 <li><a href="#">&laquo;</a></li> -->
				<li><a href="javascript:void(0);" onclick="pageChange(1);">[首页]</a></li>
				<%
					int pageNum = countNum / StringUtil.PAGESIZE;
						int yu = countNum % StringUtil.PAGESIZE;
						if (pageNum >= 2) {
							if(yu ==0){
								pageNum--;
							}
							for (int i = 2; i <= pageNum; i++) {
				%>
				<li><a href="javascript:void(0);" onclick="pageChange(<%=i%>);">[<%=i%>]
				</a></li>
				<%
					}
						}
						if (pageNum !=0) {
							if(countNum == 5){
								
							}else{
				%>
				<li><a href="javascript:void(0);"
					onclick="pageChange(<%=pageNum + 1%>);">[尾页]</a></li>
				<!-- 			<li><a href="#">&raquo;</a></li> -->
				<%
					}}
				%>
			</ul>
		</div>
		<%
			}
		%>
	</div>
	<%@ include file="/WEB-INF/jsp/include/bottom.jsp"%>
</body>
</html>